package org.rcloud.io.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.LikesMapper;
import org.rcloud.io.mapper.ShootLikeMapper;
import org.rcloud.io.mapper.ShootMapper;
import org.rcloud.io.model.Likes;
import org.rcloud.io.model.LikesVo;
import org.rcloud.io.service.LikesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/4/3.
 */
@Service(value = "LikesService")
public class LikesServiceImpl implements LikesService {
    @Autowired
    private LikesMapper likesMapper;

    @Autowired
    private ShootLikeMapper shootLikeMapper;

    @Autowired
    private ShootMapper shootMapper;

    @Override
    public ResultVo deleteByPrimaryKey(String id) {
        try {
            likesMapper.deleteByPrimaryKey(id);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo insert(Likes record) {
        if (record.equals("")||record == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                likesMapper.insert(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo insertSelective(Likes record) {
        if (record.equals("")||record == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = likesMapper.insertSelective(record);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo selectByPrimaryKey(Likes id) {
        try {
            Likes likes =likesMapper.selectByPrimaryKey(id);
            return ResultVo.setOK(likes);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo updateByPrimaryKeySelective(Likes record) {
        try {
            int i = likesMapper.updateByPrimaryKeySelective(record);
            return ResultVo.setOK(i);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo updateByPrimaryKey(Likes record) {
        try {
            likesMapper.updateByPrimaryKey(record);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo selectByVote(LikesVo record) {
        try {
            Likes likes = likesMapper.selectByVote(record);
            return ResultVo.setOK(likes);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo selectByUserId(String userid) {
        int i = shootMapper.selectByUserId(userid);
        if (i > 0) {
            return ResultVo.setError("已报名");
        } else {
            return ResultVo.setOK("未报名");
        }
    }

}
